Repository navigation
Backport #5568: [rollup] Read decorator options from tsconfig in the workflow transform - #5593
Open
github-actions[bot] wants to merge 1 commit into
Open
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…rm (#5568) `workflowTransformPlugin()` in `@workflow/rollup` runs SWC with the workflow plugin in step mode over every file that has `"use step"` or `"use workflow"`. `@workflow/nitro` puts it first in `rollup:before` ([nitro/src/index.ts#L104-L113](https://github.com/vercel/workflow/blob/e379eaf6a07696c904c28ee494cc128af2e2c772/packages/nitro/src/index.ts#L104-L113)), and `@workflow/nuxt` goes through Nitro, so it sees raw TypeScript before anything else lowers it. **Before this PR** A developer with `experimentalDecorators: true` in `tsconfig.json` runs `nitro build` on an app whose `workflows/order.ts` has an `@Injectable()` class next to a `'use step'` function. 1. Nitro's Rollup build calls the `transform` hook of `workflowTransformPlugin()` on `workflows/order.ts`. 2. The hook builds `jsc.parser` as only `{ syntax: 'typescript', tsx }` ([rollup/src/index.ts#L148-L174](https://github.com/vercel/workflow/blob/e379eaf6a07696c904c28ee494cc128af2e2c772/packages/rollup/src/index.ts#L148-L174)), with no `decorators`, and `jsc.transform` has no `legacyDecorator` or `decoratorMetadata`. 3. SWC reaches `@Injectable()` with decorator parsing off. 4. The build fails with `x Expression expected` (or ``Unexpected token `@` `` on a method decorator). **After this PR** Same developer, same `nitro build`. 1. Same as above through step 1. 2. The hook calls `getCachedDecoratorOptions(process.cwd())` from `@workflow/builders`. This is the function `applySwcTransform` already used internally, now exported so both places share one cache. It finds the nearest `tsconfig.json` or `jsconfig.json`, follows `extends`, and reads it once per directory. 3. `experimentalDecorators: true` gives `decorators: true` and `legacyDecorator: true`, plus `decoratorMetadata: true` when `emitDecoratorMetadata` is also on ([config-helpers.ts#L52-L62](https://github.com/vercel/workflow/blob/e379eaf6a07696c904c28ee494cc128af2e2c772/packages/builders/src/config-helpers.ts#L52-L62)). 4. SWC parses the decorators, lowers them to `_ts_decorate(...)`, and the step registers as `step//./workflows/order//chargeOrder`. 5. With `experimentalDecorators` off or no tsconfig at all, all three values are `false`, so the transform behaves exactly as it does today. Signed-off-by: Abhiram Shaji <write4abhiram@gmail.com> Co-authored-by: Peter Wielander <mittgfu@gmail.com> Co-authored-by: Peter Wielander <peter.wielander@vercel.com> Signed-off-by: Abhiram Shaji <write4abhiram@gmail.com>
2 of 3 tasks
🦋 Changeset detectedLatest commit: 50b9778 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Comment on lines
+89
to
+99
| it('follows tsconfig extends to find experimentalDecorators', async () => { | ||
| const options = await swcOptionsFor( | ||
| projectWith({ | ||
| 'tsconfig.base.json': { | ||
| compilerOptions: { experimentalDecorators: true }, | ||
| }, | ||
| 'tsconfig.json': { extends: './tsconfig.base.json' }, | ||
| }) | ||
| ); | ||
|
|
||
| expect(options.jsc?.parser?.decorators).toBe(true); |
Contributor
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated backport of #5568 to
stable(backport job run).AI recommendation: This fixes a build failure: Nitro and Nuxt builds crash with
Expression expectedon workflow files that use decorators whileexperimentalDecoratorsis on. Onstable,@workflow/rolluphas the same parser config with no decorator options, and the tsconfig decorator helpers in@workflow/buildersalready exist there. The newgetCachedDecoratorOptionsexport only shares the existing cache, and the patch adds tests for the fix.Merge conflicts were resolved by AI (opencode with
anthropic/claude-opus-5.5). Please review the conflict resolution carefully before merging.